package com.kl.forum.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kl.forum.dao.KindBannerMapper;
import com.kl.forum.dao.TagKindDicMapper;
import com.kl.forum.entity.Banner;
import com.kl.forum.entity.KindBanner;
import com.kl.forum.entity.TagKindDic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TagKindDicService {
    @Autowired
    private TagKindDicMapper tagKindDicMapper;
    @Autowired
    private KindBannerMapper kindBannerMapper;

    public PageInfo<TagKindDic> findTagKind(Integer tagId, Integer pageNum , Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        Map map =new HashMap();
        map.put("tagId",tagId);
        List<TagKindDic> list=tagKindDicMapper.findTagKind(map);
        PageInfo<TagKindDic> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    public TagKindDic findKindByKindId(Integer id) {
        TagKindDic tagKindDic=  tagKindDicMapper.findKindByKindId(id);
        List<KindBanner> bannerList=kindBannerMapper.findKindBanner(tagKindDic.getId());
        if (bannerList!=null){
            tagKindDic.setListBanner(bannerList);
        }

        return  tagKindDic;
    }
}
